<?php
/**
 * Created by PhpStorm.
 * User: yuyiwen
 * Date: 2018/9/18
 * Time: 上午9:58
 */

namespace app\admin\controller;


use think\Config;
use think\Request;

class Qrcode extends Common
{
    public function change ()
    {
        $qrcode = db('config')->where(['name'=>'qrcode'])->find();
        $this->assign('qrcode' , $qrcode['value']);
        return view();
    }

    public function store ()
    {

        if (Request::instance()->isAjax()) {
            $file = \request()->file('src');
            if ($file)
            {
                $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
                if($info){
//                     成功上传后 获取上传信息
//                     输出 jpg

                    $msg['src'] = Config::get('view_replace_str')['__UPLOAD__'].$info->getSaveName();
                    $msg['savename'] = $info->getSaveName();
                    $msg['status'] = 1;
                    db('config')->where(['name'=>'qrcode'])->delete();
                    db('config')->insert(['id'=>1,'name'=>'qrcode' , 'value'=>$msg['src']]);
//                    $image = Image::open('.'.$msg['src']);
//                    $thumb_path = $info->getPath() . '_thumb';
//                    file_exists($thumb_path)  || mkdir($thumb_path , 0777 , true);
////                    echo $info->getPath();die;
//
//                    $image->thumb(150, 150)->save($thumb_path .'/'. $info->getBasename());

                }else{
                    // 上传失败获取错误信息
                    $msg['msg'] = $file->getError();
                    $msg['status'] = 0;
                }
                return json($msg);
            }
        }
    }
}